package com.xqy.wexmini.utils.oss;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.xqy.wexmini.utils.StringUtilsTest;
import com.xqy.wexmini.utils.baiduUtils;


import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


public class Fileload {
    private OSSClient client;

    private String endpoint="oss-cn-shenzhen.aliyuncs.com";

    private String bucket="vegetable666";

    private String AccessKeyId="LTAI5tKyk4i6D9VgRFgLn5Uq";

    private String AccessKeyIdSecret="JXJZHdZhOGWmwuObYpZgSQbgvUBdYP";

    public Fileload() {
        client = new OSSClient(this.endpoint,AccessKeyId,AccessKeyIdSecret);
    }



/*    public String upload(InputStream inputStream, String name, String contentType) {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType(contentType);
        client.putObject(bucket,name,inputStream,metadata);
        return "https://" + bucket + "." + endpoint + "/" + name;
    }*/
    //传递带有汉字url
    public String upload(InputStream inputStream, String name, String contentType) {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType(contentType);
        String s = StringUtilsTest.toPinyin(name);
        client.putObject(bucket,s,inputStream,metadata);
        System.out.println(s);
        return "https://" + bucket + "." + endpoint + "/" + s;
    }

    //指定文件名称删除文件
    public String deletelingshi(String name){

        client.deleteObject(bucket,name);
        return "删除成功";
    }
    //扫描图片
/*    public String shaomiao(String name){
        return baiduUtils.ingredient("https://"+bucket+"."+endpoint+"/"+name);
    }*/

}
